package store.lunangangster.bpmn.converter;

import javax.xml.stream.XMLStreamReader;
import store.lunangangster.bpmn.converter.parser.HumanPerformerParser;
import store.lunangangster.bpmn.converter.parser.PotentialOwnerParser;
import store.lunangangster.bpmn.model.BpmnModel;
import store.lunangangster.bpmn.model.UserTask;
import store.lunangangster.bpmn.util.BpmnXmlUtil;

public class UserTaskConverter extends TaskConverter {

  public UserTaskConverter() {
    super();
    addChildElementParser(new PotentialOwnerParser());
    addChildElementParser(new HumanPerformerParser());
  }

  /**
   * 从xml文件输入流中解析出{@link UserTask}对象
   * @param xsr   xml文件输入流
   */
  @Override
  protected UserTask convertToElement(XMLStreamReader xsr, BpmnModel model) throws Exception {

    UserTask userTask = null;

    userTask = new UserTask();

    BpmnXmlUtil.addXmlLocation(xsr, userTask);

    this.parseChildElement(xsr, userTask, this.getTargetName(), model);
    return userTask;
  }

  /**
   * 获取当前元素解析器的作用元素名
   * @return 待解析元素名
   */
  @Override
  public String getTargetName() {
    return ELEMENT_TASK_USER;
  }
}
